home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / PInterfaces / Disassembler.p < prev    next >
Encoding:
Text File  |  1994-07-27  |  25.8 KB  |  483 lines  |  [TEXT/MPS ]

  1. {*---------------------------------------------------------------------------*
  2.  |                                                                           |
  3.  |                          <<< Disassembler.p >>>                           |
  4.  |                                                                           |
  5.  |                     Power[PC] Disassembler Interfaces                     |
  6.  |                                                                           |
  7.  |                               Ira L. Ruben                                |
  8.  |                                  5/9/93                                   |
  9.  |                                                                                                                                                     |
  10.  |                                        Translated from C to Pascal by                                                 |
  11.  |                                                             Greg Branche                                                                 |
  12.  |                                                                 7/20/94                                                                     |
  13.  |                                                                           |
  14.  |                  Copyright Apple Computer, Inc. 1993-1994                 |
  15.  |                           All rights reserved.                            |
  16.  |                                                                           |
  17.  *---------------------------------------------------------------------------*}
  18.  
  19. {$IFC UNDEFINED UsingIncludes}
  20. {$SETC UsingIncludes := 0}
  21. {$ENDC}
  22.  
  23. {$IFC NOT UsingIncludes}
  24.  UNIT Disassembler;
  25.  INTERFACE
  26. {$ENDC}
  27.  
  28. {$IFC UNDEFINED __DISASSEMBLER__}
  29. {$SETC __DISASSEMBLER__ := 1}
  30.  
  31. {$I+}
  32. {$SETC DisassemblerIncludes := UsingIncludes}
  33. {$SETC UsingIncludes := 1}
  34.  
  35.  
  36. {$IFC UNDEFINED __TYPES__}
  37. {$I Types.p}
  38. {$ENDC}
  39.  
  40. {$PUSH}
  41.  
  42. CONST
  43.  
  44. {* The following defines the "options" that can be passed to the disassembler.  All    *}
  45. {* except ONE of the target architecture options have preset defaults.                            *}
  46.  
  47.                                                                                 {* Target architecture (one must be set):        *}
  48.     Disassemble_Power             = $00000001;        {*    Power                                                                    *}
  49.     Disassemble_PowerPC32     = $00000002;        {*       32-bitPowerPC                                            *}
  50.     Disassemble_PowerPC64  = $00000004;        {*          64-bit PowerPC                                     *}
  51.     Disassemble_PowerPC601 = $00000008;        {*             PowerPC 601                                    *}
  52.                                                                                 {* Error detection options:                         *}
  53.     Disassemble_RsvBitsErr = $80000000;        {*    invalid reserved bits is error                *}
  54.     Disassemble_FieldErr     = $40000000;        {*    invalid field (regs, BO, etc.) error    *}
  55.                                                                                 {* Formatting options (reverses presets):        *}
  56.     Disassemble_Extended     = $08000000;        {*    extended mnemonics (ppc only)                    *}
  57.     Disassemble_BasicComm     = $04000000;        {*    basic form in comment if extended            *}
  58.     Disassemble_DecSI             = $02000000;        {*    SI fields formatted as decimal                *}
  59.     Disassemble_DecUI             = $01000000;        {*    UI fields formatted as decimal                *}
  60.     Disassemble_DecField     = $00800000;        {*         fields shown as decimal                                *}
  61.     Disassemble_DecOffset     = $00400000;        {*    D of D(RA) shown in decimal                        *}
  62.     Disassemble_DecPCRel     = $00200000;        {*    $+decimal offset instead of $+hex            *}
  63.     Disassemble_DollarHex     = $00100000;        {*    $XXX... instead of 0xXXX...                        *}
  64.     Disassemble_Hex2sComp     = $00080000;        {*         negative hex shown in 2s compliment        *}
  65.     Disassemble_MinHex         = $00040000;        {*        min nbr of hex digits for values >= 0    *}
  66.     Disassemble_CRBits         = $00020000;        {*    crN_LT, crN_GT, crN_EQ, crN_SO                *}
  67.     Disassemble_CRFltBits  = $00010000;        {*        crN_FX, crN_FEX, crN_VX, crN_OX                *}
  68.     Disassemble_BranchBO     = $00008000;        {*        branch BO meaning if not extended            *}
  69.     Disassemble_TrapTO          = $00004000;        {*        trap TO meaning if not extended                *}
  70.     Disassemble_IBM                 = $00002000;        {*    IBM assembler conventions                            *}
  71.  
  72. {*
  73. Except for the target architecture options, ONE of which must be set, here's an explanation
  74. of the other options and their preset default.
  75.      
  76. Disassemble_RsvBitsErr - Reserved bits in PowerPC instructions are considered a "warning"
  77.                                                  and causes the return status to be set to indicate whether
  78.                                                  reserved bits were incorrectly coded (1's that should be 0's and
  79.                                                  vice versa). The option indicates incorrectly coded reserved bits
  80.                                                  cause the instruction to be treated as "invalid".
  81.  
  82. Disassemble_FieldErr     - Attempted use of a field value not valid for a target is
  83.                                                  considered a "warning" and causes the return status to be set to
  84.                                                  indicate that fact.  The option indicates that use of a field
  85.                                                  whose value is not valid for the target is "invalid".  An example
  86.                                                  of an invalid field would be the use of a SPR not supported for
  87.                                                  the target architecture like the "HIDx" SPRs which are only valid
  88.                                                  for the 601.  Another example is non zero bits in the bc[l][a] BO
  89.                                                  field that are supposed to be zero.  Note this is NOT the same as
  90.                                                  Disassemble_RsvBitsErr.  But if a field has NO valid decoding
  91.                                                  value for ANY target, that is always considered as an invalid
  92.                                                  instruction.
  93.  
  94. Disassemble_Extended     - Extended mnemonics are NOT generated.  The option allows the
  95.                                                  extended mnemonic generation (recommended).  Only PowerPC32,
  96.                                                  PowerPC64, and PowerPC32 and PowerPC64 instructions used on the
  97.                                                  601 are supported.
  98.  
  99. Disassemble_BasicComm     - The basic instruction form is NOT placed in the comment field.
  100.                                                  The option causes the basic form of the instruction to be placed
  101.                                                  in the comment if an extended mnemonic is generated for it.  This
  102.                                                  option is not recommended since it is mainly for debugging and it
  103.                                                  tends to "clutter" up the comment field making it harder to see
  104.                                                  branch addresses.
  105.  
  106. Disassemble_DecSI             - SIs (signed immediate integers) are formatted as hex.  The option
  107.                                                  causes SI operands to be generated as decimal integers.
  108.  
  109. Disassemble_DecUI             - UIs (unsigned immediate integers) are formatted as hex.  The
  110.                                                  option causes UI operands to be generated as decimal integers.
  111.  
  112. Disassemble_DecField     - All fields (e.g., shift/rotate constants) are shown as hex.  The
  113.                                                  option causes the offsets to be generated as decimal integers.
  114.  
  115. Disassemble_DecOffset  - The "D" offsets in operands of the form D(RA) are shown in hex.
  116.                                                  The option causes these to be generated as decimal.
  117.  
  118. Disassemble_DecPCRel     - PC-relative branch addresses are formatted as "$+n" or "$-n", with
  119.                                                  the offset ("n") generated in hex.  The option causes the offset
  120.                                                  to be generated as decimal.
  121.  
  122. Disassemble_DollarHex     - Hex values are prefixed with "0x".  The option causes hex values
  123.                                                  to be formatted as "$XXX...".
  124.  
  125. Disassemble_Hex2sComp     - Signed negative values that are shown in hex are negated and
  126.                                                  prefixed with a "-" (e.g. "-0x0001").  The option causes these
  127.                                                  values to be shown in their two's complement form (e.g.,
  128.                                                  "0xFFFFFFFF").
  129.  
  130. Disassemble_MinHex         - Positive hex values or negated negative values are always shown
  131.                                                  with the number of digits attempting to indicate the size of the
  132.                                                  instruction field which produced the value or the implied value
  133.                                                  size.  Thus 32-bit target addresses are shown as 8 hex digits,
  134.                                                  16-bit field values are shown with 4 hex digits, byte field values
  135.                                                  as 2 hex digits.  5 or six-bit values are also shown as 2 hex
  136.                                                  digits since the minimum is always at least 2. The option forces
  137.                                                  the generation to always use 2 as the minimum even if the value
  138.                                                  came from a bigger field (e.g., "0x1234" address, "0x01" or
  139.                                                  "-0x01" from a 16-bit field).
  140.  
  141. Disassemble_CRBits          - Condition register field bits are referenced as bit numbers 0:31
  142.                                                  in the basic instruction operand forms.  The option causes these
  143.                                                  bits to be referenced using the format “crN_X”, where N is a 4-bit
  144.                                                  CR field (0:7) and X is the bit “name” in the field (“LT”, “GT”,
  145.                                                  “EQ”, “SO” for bits 0, 1, 2, and 3 respectively).  Note, this
  146.                                                  notation is always used with extended mnemonics.
  147.  
  148. Disassemble_CRFltBits  - Condition register field bits are referenced as bit numbers 0:31
  149.                                                  in the basic instruction operand forms.  The option is identical
  150.                                                  to Disassemble_CRBits to generate the references as “crN_X”,
  151.                                                  except that the bits (X) are referenced as “FX”, “FEX”, “VX” and
  152.                                                  “OX” for the four bits 0,1, 2, and 3 respectively.  This option
  153.                                                  can be used if the context of floating-point operations, but it's
  154.                                                  up to the caller to determine that context.
  155.  
  156. Disassemble_BranchBO     - Branch test BO encodings are referenced as values 0:31 in the 
  157.                                                  basic instruction operand forms.  The option causes the BO value
  158.                                                  to be referenced as more meaningful names (e.g., "dCTR_NZERO_NOT",
  159.                                                  "ALWAYS", etc.).
  160.                                                  
  161. Disassemble_TrapTO         - Trap TO operand encodings are referenced as values 0:31 in the 
  162.                                                   basic instruction operand forms.  The option causes the TO value
  163.                                                  to be an expression of the form "x|y|...", where the "x", "y",
  164.                                                  and so are the meaning of each of the five TO bits; "LT", "GT",
  165.                                                  "EQ", "LOW", "HI" for bits 0, 1, 2, 3, and 4 respectively.
  166.  
  167. Disassemble_IBM                 - Apple assembler conventions are used for comments and invalid
  168.                                                  instructions.  The option causes IBM assembler conventions to be
  169.                                                  used for these.  A “#” is used instead of a “;” as the comment
  170.                                                  character, and “.long” is used instead of “dc.l” for the invalid
  171.                                                  instruction directive mnemonic.
  172.  
  173.                                   [Are we having fun yet?]
  174. *}
  175.  
  176. {* The following defines a set of the above options which seem to give "acceptable"         *}
  177. {* results:                                                                                                                                                            *}
  178.  
  179.     DisStdOptions = (Disassemble_Extended  +            {* permit extended mnemonics                *}
  180.                    Disassemble_DecSI     +            {* decimal SIs but hex UIs                    *}
  181.                    Disassemble_DecField  +            {* decimal field numbers                        *}
  182.                    Disassemble_BranchBO  +            {* meaning of branch BO                            *}
  183.                                      Disassemble_TrapTO         +            {* meaning of trap TO                                *}
  184.                                      Disassemble_CRBits);                    {* CR bits references as crN_X            *}
  185.                                              
  186.  
  187.     {* Return status flags:                                                                                                                        *}
  188.     
  189.     Disassembler_OK                      = $0001;        {* instruction successfully decoded                    *}
  190.     Disassembler_InvRsvBits      = $0002;        {* invalidly coded reserved bits                        *}
  191.     Disassembler_InvField          = $0004;        {* invalidly coded field(s)                                    *}
  192.     Disassembler_InvSprMaybe     = $0008;        {* possibly invalid SPR                                            *}
  193.     Disassembler_601Power             = $0010;        {* power instruction used with 601                    *}
  194.     Disassembler_Privileged      = $0020;        {* privileged instruction                                        *}
  195.     Disassembler_Optional          = $0040;        {* optional instruction                                            *}
  196.     Disassembler_Branch                 = $0080;        {* branch instruction                                                *}
  197.     Disassembler_601SPR                 = $0100;        {* SPR valid only for 601 has been used            *}
  198.     Disassembler_HasExtended  = $4000;        {* possible extended mnemonic                                *}
  199.     Disassembler_ExtendedUsed = $8000;        {* the extended mnemonic was generated            *}
  200.  
  201.     DisInvalid                                 = $0000;        {*       invalid instruction                                *}
  202.  
  203.     {*
  204.     Unless DisInvalid (0) is returned as the function result, Disassembler_OK will always be
  205.     set.  The other flags have the following meaning:
  206.     
  207.     Disassembler_InvRsvBits        - The instruction had some or all of its reserved bits
  208.                                                             incorrectly coded, and the Disassemble_RsvBitsErr option was
  209.                                                             NOT set.  This is something like a "warning". With the option
  210.                                                             set, this condition is considered as an "error" and the
  211.                                                             "invalid instruction" is generated ("dc.l 0xXXXXXXXX").
  212.     
  213.     Disassembler_InvField            -    The instruction had fields incorrectly coded for the
  214.                                                             target, but is is still valid for some target (e.g., not
  215.                                                             valid for the 601 but valid for the PowerPC64), and the
  216.                                                             Disassemble_FieldErr option was NOT set.
  217.     
  218.     Disassembler_InvSprMaybe    - A mfspr or mtspr instruction references a POSSIBLY invalid
  219.                                                             SPR.  This occurs when an SPR value is not for one of the
  220.                                                             predefined SPR names (see list above) and there is no lookup
  221.                                                             routine, or it does not supply a substitution name.  In that
  222.                                                             case the SPR register number is generated.  Since there is
  223.                                                             no way of the disassembler knowing whether the register is
  224.                                                             valid for the architecture of interest, this flag is set 
  225.                                                             instead of Disassembler_InvField to indicate the possibility
  226.                                                             that the SPR may be invalid.
  227.     
  228.     Disassembler_601Power            - The options specified that the target architecture is the
  229.                                                             601 (Disassemble_PowerPC601), and a Power instruction was
  230.                                                             disassembled.  The 601 is basically an ORing of the Power
  231.                                                             and PowerPC32 architectures.  But this flag could be useful
  232.                                                             for "weeding" Power instructions out in preparation for use
  233.                                                             on a "pure" PowerPC32 or PowerPC64 architecture.
  234.     
  235.     Disassembler_601SPR                - The options specified that the target architecture is the
  236.                                                             601 (Disassemble_PowerPC601), and a mfspr or mtspr
  237.                                                             instruction references a SPR valid ONLY for the 601.
  238.                                                             
  239.     Disassembler_Privileged        - The instruction is privileged.
  240.                                                             
  241.     Disassembler_Optional            - The instruction is optional.
  242.     
  243.     Disassembler_Branch                -    Branch instruction; bc[l][a], b[l][a], bclr[l], bcctr[l] and
  244.                                                             Power bcr[l], bcc[l].  If any of these instructions are
  245.                                                             processed the flag is set.  Branches are signaled because
  246.                                                             the caller might want to do some additional processing on
  247.                                                             these.  For example, a debugger might want to dynamically
  248.                                                             show which way the branch is taken, or static analysis might
  249.                                                             want to know possible exit points from a function or show
  250.                                                             the branch in some graphical way.  Although the caller could
  251.                                                             determine if the instruction is a branch, the disassembler
  252.                                                             always has to classify the instructions passed to it, so
  253.                                                             there is no sense having both do it if the information is
  254.                                                             already available.  Note, the caller might still, however,
  255.                                                             need to extract the BO and BI fields to determine the
  256.                                                             condition of the branch, but at least it only needs to be
  257.                                                             done when the flag is set.
  258.     
  259.     Disassembler_HasExtended     - The instruction POSSIBLY has an extended mnemonic, whether
  260.                                                             used or not used (as a function of the Disassemble_Extended
  261.                                                             option). Note, "possibly has an extended mnemonic"; the
  262.                                                             instruction could have extendeds, but not for all
  263.                                                             values of its operands.
  264.                                                             
  265.     Disassembler_ExtendedUsed - The instruction has an extended mnemonic, and it was used
  266.                                                             because the option (Disassemble_Extended) permits it.  The
  267.                                                             operand is formatted appropriate to the extended mnemonic.
  268.                                                             Whether the original basic form is placed in the comment or
  269.                                                             not is controlled by the Disassemble_BasicComm option.
  270.     *}
  271.     
  272.     
  273. {* All assembler options are of type DisassemblerOptions:                                                                *}
  274.  
  275. TYPE
  276.     DisassemblerOptions =    LongInt;
  277.  
  278.     DisassemblerStatus = Integer;                                {* disassembler return status (see above)    *}
  279.  
  280. {* The optional lookup function (NULL could be passed) is used to allow the caller to        *}
  281. {* substitute name strings for various objects that can occur in an operand.  It should    *}
  282. {* return a pointer to a non-null string if substitution is desired.  If NULL or a null *}
  283. {* string is returned, the disassembler uses its own default names.  The following            *}
  284. {* defines the possible substitable objects:                                                                                        *}
  285.  
  286.     DisassemblerLookupType    =    (                                {* Types of substitutable objects:                    *}
  287.         Disassembler_Lookup_GPRegister,                    {*            general purpose register                        *}
  288.         Disassembler_Lookup_FPRegister,                    {*            floating point register                            *}
  289.         Disassembler_Lookup_UImmediate,                    {*            unsigned immediate value                        *}
  290.         Disassembler_Lookup_SImmediate,                    {*            signed (32-bit) immediate value            *}
  291.         Disassembler_Lookup_AbsAddress,                    {*            absolute addresse                                        *}
  292.         Disassembler_Lookup_RelAddress,                    {*            relocatable addresse                                *}
  293.         Disassembler_Lookup_RegOffset,                    {*            offset from a base register                    *}
  294.         Disassembler_Lookup_SPRegister                    {*            special purpose register                        *}
  295.     );
  296.  
  297.  
  298. {* Here's a definition of an object (value) which is a function of each                                 *}
  299. {* DisassemblerLookupType:                                                                                                                            *}
  300.  
  301.     {$ALIGN MAC68K}
  302.     DisLookupValue = RECORD                                        {* A "meaningful" name for each value type:    *}
  303.         CASE INTEGER OF
  304.         0:    (gpr:                    LongInt;);                        {*        Disassembler_Lookup_GPRegister                *}
  305.         1:    (fpr:                    LongInt;);                        {*        Disassembler_Lookup_FPRegister                *}
  306.         2:    (ui:                    LongInt;);                        {*        Disassembler_Lookup_UImmediate                *}
  307.         3:    (si:                    LongInt;);                        {*        Disassembler_Lookup_SImmediate                *}
  308.         4:    (absAddress:    LongInt;);                        {*        Disassembler_Lookup_AbsAddress                *}
  309.         5:    (relAddress:    LongInt;);                        {*        Disassembler_Lookup_RelAddress                *}
  310.         6:    (spr:                    LongInt;);                        {*         Disassembler_Lookup_SPRegister                *}
  311.         7:    (    {    regOffset}
  312.                     offset:            Integer;
  313.                     baseReg:        Integer;
  314.                 );                                                                    {*        Disassembler_Lookup_RegOffset                    *}
  315.     END;
  316.     {$ALIGN RESET}
  317.  
  318.     DisLookupValuePtr = ^DisLookupValue;
  319.  
  320. {* Finally, at long last, here's the definition of the disassembler...                                    *}
  321.  
  322. FUNCTION ppcDisassembler(            instruction     : LongIntPtr; 
  323.                                                             dstAdjust            :    LongInt;
  324.                                                             options                :    DisassemblerOptions;
  325.                                                             mnemonic            :    CStringPtr;
  326.                                                             operand                :    CStringPtr;
  327.                                                             comment                :    CStringPtr;
  328.                                                             refCon                : UNIV Ptr;
  329.                                                             lookupRoutine    : UNIV Ptr) : DisassemblerStatus;
  330.     {*
  331.     Takes the four bytes pointed to by instruction and disassembles it, placing the mnemonic,
  332.     operand, and comment in the strings provided.  The caller is then free to format or use
  333.     the output strings any way appropriate to the application.  Any of these strings may be a
  334.     null pointer, in which case that portion of the disassembled instruction is not returned.
  335.     If they are not null, it is ASSUMED that the associated buffers are large enough to hold
  336.     the disassembled output.
  337.     
  338.     Comments are formatted starting with a "; " (or "#" if the appropriate "IBM" option is
  339.     set).  Invalid instructions generate a "dc.l" (".long" for IBM), an operand of the form
  340.     0xXXXXXXXX showing the actual instruction, and a comment with a message indicating what
  341.     is wrong with the instruction.
  342.     
  343.     For PC-relative branches, the comment generated is the destination address, the only
  344.     address that the disassembler "knows" about is the address of the code pointed to by the
  345.     instruction.  Generally, that may be a buffer that has no relation to "reality", i.e.,
  346.     the actual code loaded into the buffer.  Therefore, to allow the address comment to be
  347.     mapped back to some actual address, the caller may specify an adjustment factor,
  348.     specified by dstAdjust that is ADDED to the value that normally would be placed in the
  349.     comment.
  350.  
  351.     Many operands usually consist of registers, absolute and relocatable addresses, and
  352.     signed and unsigned values.  In places where these occur, the disassembler can call a
  353.     user specified routine to do the substitution using the lookupRoutine parameter if it
  354.     is not NULL.  A "refcon" is passed to the disassembler that is, in turn, passed on to
  355.     the lookup routine to allow a communication path between the disassembler caller and its
  356.     lookup routine.  The refcon can be anything.  The disassembler does not look at it.
  357.     
  358.     The caller also can control some aspects of the formatting with the DisassemblerOptions
  359.     as described above.  The options also specify the target architecture; Power, PowerPC32,
  360.     PowerPC64, or PowerPC601.
  361.     
  362.     The disassembler returns as its function result the DisassemblerStatus.  This may be
  363.     tested for 0 ("false" or DisInvalid defined below) to find out if an invalid instruction
  364.     was detected.  For valid instructions, the DisassemblerStatus is non zero and indicates
  365.     various attributes about the instruction as follows:                                                                    *}
  366.     
  367. {* The "lookup" substitution routine for the objects is defined as follows:
  368.  
  369. FUNCTION DisassemblerLookups(            refCon                    :    UNIV Ptr,
  370.                                                                      cia                            :    LongIntPtr, 
  371.                                                                     lookupType            :    DisassemblerLookupType,
  372.                                                                     thingToReplace    :    DisLookupValue) : CStringPtr;
  373.  
  374.     where, refCon                  = A "reference constant" that can be used as a communication link
  375.                                                      between the lookup routine and the caller of the disassembler.
  376.                                                      It is the same refCon passed to the disassembler.
  377.  
  378.                     cia                       = The instruction address passed to the disassembler.
  379.  
  380.                     lookupType and
  381.                     thingToReplace = The kind of object and the associated value of that object to be
  382.                                                      replaced.  As defined by DisLookupValue, the thingToReplace has
  383.                                                      the following value for each lookupType.
  384.  
  385.                                                      lookupType                                                value            
  386.                                                      ============================================= 
  387.                                                      Disassembler_Lookup_GPRegister        0:31                
  388.                                                      Disassembler_Lookup_FPRegister        0:31                
  389.                                                      Disassembler_Lookup_UImmediate        integer    
  390.                                                      Disassembler_Lookup_SImmediate        integer        
  391.                                    Disassembler_Lookup_AbsAddress        address [1]
  392.                                                      Disassembler_Lookup_RelAddress        address [2]
  393.                                                      Disassembler_Lookup_RegOffset        D + Ra  [3]
  394.                                                      Disassembler_Lookup_SPRegister        spr            [4]
  395.                                                      =============================================
  396.  
  397.                                                       Notes: 
  398.                                                      
  399.                                                      [1] This is an absolute target branch address, i.e., the "a" bit
  400.                                                               in the branch instruction IS set.  The passed absAddress
  401.                                                              is the address contained in the instruction.
  402.                                                              
  403.                                                      [2] This is a relocatable target branch address, i.e., the "a"
  404.                                                               bit in the branch instruction was NOT set.  The relAddress
  405.                                                              is relative to the current instruction address adjusted
  406.                                                              by the dstAdjust.  Thus,
  407.                                                              
  408.                                                              relAddress = destinationAddress + dstAdjust + cia
  409.                                                              
  410.                                                              where cia is the current instruction address, i.e, the value
  411.                                                              of the instruction address passed to the disassembler.
  412.                                                                             
  413.                                                      [3] Both the offset (D) and base register (Ra) are passed.  The
  414.                                                               DisLookupValue.regOffset value defines how they are packed
  415.                                                              in the thingToReplace.  The offset should be assigned to a
  416.                                                              long to get its true 32-bit value.  It is valid to pass it
  417.                                                              as a signed short since the instruction field from which it
  418.                                                              came is never more than 16 bits wide.
  419.                                                      
  420.                                                      [4] The lookup for SPRs is slightly different in that it is only
  421.                                                               done as an ESCAPE mechanism, i.e., only when the SPR number is
  422.                                                              NOT one of the predefined Power, 601, PowerPC32, or
  423.                                                              PowerPC64 SPR names.  This is done because a different
  424.                                                              PowerPC architectures can have additional SPRs specific to
  425.                                                              those architectures!  The lookup routine is called only if
  426.                                                              the SPR is NOT one of the following predefined numbers:
  427.                                                                     
  428.                                                                 0 MQ      272 SPRG0   528 IBAT0U   536 DBAT0U   1008 HID0
  429.                                                                 1 XER     273 SPRG1   529 IBAT0L   537 DBAT0L   1009 HID1
  430.                                                                 4 RTCU    274 SPRG2   530 IBAT1U   538 DBAT1U   1010 IABR
  431.                                                                 5 RTCL    275 SPRG3   531 IBAT1L   539 DBAT1L   1013 DABR
  432.                                                                 6 DEC     280 ASR     532 IBAT2U   540 DBAT2U   1023 PIR
  433.                                                                 8 LR      282 EAR     533 IBAT2L   541 DBAT2L
  434.                                                                 9 CTR     284 TB      534 IBAT3U   542 DBAT3U
  435.                                                              18 DSIAR   285 TBU     535 IBAT3L   543 DBAT3L
  436.                                                              19 DAR     287 PVR
  437.                                                              22 DEC
  438.                                                              25 SDR1
  439.                                                              26 SRR0
  440.                                                              27 SRR1
  441.                                                             
  442.                                                              Not all of these SPRs are valid for all targets.  The
  443.                                                              disassembler will check to see if these SPRs are valid for
  444.                                                              the specified target architecture.  If they are not, the SPR
  445.                                                              number is treated as an invalid field and processed
  446.                                                              according to the Disassemble_FieldErr option, i.e., it’s
  447.                                                              accepted but returns a status warning, or the instruction is
  448.                                                              treated as invalid (“DC.L 0xXXXXXXXX”).
  449.  
  450.                                                              SPR numbers which are not on the list, and also do not have
  451.                                                              a lookup substitution name, are always accepted.  But since
  452.                                                              there is no way for the disassembler to validate these
  453.                                                              against the target, the Disassembler_InvSprMaybe return
  454.                                                              status flag will be set.                                                                    *}
  455.                                                              
  456. {* NOTES: 1. The disassembler library uses the convention that, with the exception of     *}
  457. {*                     the called routine name itself, i.e., "ppcDisassembler", all externally         *}
  458. {*                     visible names (linker symbols and macro names) begin with the letters "dis"*}
  459. {*                      (in any case).  The user should keep this in mind to avoid possible name     *}
  460. {*                      conflicts.                                                                                                                                    *}
  461.  
  462. {*                2. Except for statically declared (read only) tables, the disassembler uses no*}
  463. {*                     other global data.                                                                                                                    *}
  464.  
  465. {*                3. The disassembler is fully self contained in that it has no explicit                 *}
  466. {*                     references to any runtime library routines (e.g., strcpy).  There may,         *}
  467. {*                     however, be implicit references generated by the (C) compiler.                            *}
  468.  
  469. {*                4. The disassembler is written in standard ANSI C making it possible to easily*}
  470. {*                     port to other platforms.                                                                                                        *}
  471.  
  472.  
  473. {$ALIGN RESET}
  474. {$POP}
  475.  
  476. {$SETC UsingIncludes := DisassemblerIncludes}
  477.  
  478. {$ENDC} {__DISASSEMBLER__}
  479.  
  480. {$IFC NOT UsingIncludes}
  481.  END.
  482. {$ENDC}
  483.